package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;

import java.util.HashMap;
import java.util.List;

public class LeafAdapter extends BaseQuickAdapter<Integer,LeafAdapter.ViewHolder> {
    private HashMap<Integer, EditText> map = new HashMap<>();
    public LeafAdapter(@Nullable List<Integer> data) {
        super(R.layout.item_leaf_sort, data);
    }



    @Override
    protected void convert(ViewHolder helper, Integer item) {
        map.put(helper.getAdapterPosition(), helper.ed_item_leaf);
    }


    public double[] getAllEdtextData(){
        double a[] = new double[map.size()];
        int position = 0;
        for (EditText value : map.values()) {
            if(value.getText().toString().trim().equals("")){
                return null;
            }
            a[position] = Double.parseDouble(value.getText().toString().trim());
            position++;
        }
        return a;
    }

    public void clearAllData(){
        for (EditText value : map.values()) {
             value.setText("");
        }
        map.clear();
    }

    class ViewHolder extends BaseViewHolder {
        public EditText ed_item_leaf;

        ViewHolder(View itemView) {
            super(itemView);
            ed_item_leaf = itemView.findViewById(R.id.ed_item_leaf);
        }
    }

}
